﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/ResponsiveTheme.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TaggerApp.Admin.Pages.LoanDeviceList.Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style>  body {padding-top: 60px;padding-bottom: 40px;}      </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    Status: <asp:DropDownList ID="dropdownStatus" runat="server" AutoPostBack="true" AppendDataBoundItems="true" DataSourceID="SqlDSStatus" DataTextField="status" DataValueField="status">
                         <asp:listitem text="All" value="" Selected="True"></asp:listitem>
            </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDSStatus" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [status] FROM [tblLoanDevice]"></asp:SqlDataSource>
    Loan Time: <asp:DropDownList ID="dropDownTime" runat="server" AutoPostBack="true" AppendDataBoundItems="true" DataSourceID="SqlDSLoanTime" DataTextField="loanTimeDesc" DataValueField="loanTimeID">
                                 <asp:listitem text="All" value="" Selected="True"></asp:listitem>
               </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDSLoanTime" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [tblLoanTime]"></asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDSDevices" CssClass="table table-bordered table-hover" DataKeyNames="loanID" >
        <Columns>
            <asp:TemplateField HeaderText="Product Name" SortExpression="productName">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("productName") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <a href="../EditLoanedDeviceInfo/Default.aspx?id=<%# Eval("loanID")%>"><%# Eval("productName") %></a>
        </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="loanerName" HeaderText="Loaner Name" SortExpression="loanerName"/>
            <asp:TemplateField HeaderText="Date Borrowed" SortExpression="dateBorrow">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("dateBorrow", "{0:d}") %>' ReadOnly="true"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("dateBorrow", "{0:d}") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Loan Length" SortExpression="loanTimeID">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDSTime" DataTextField="loanTimeDesc" DataValueField="loanTimeID" SelectedValue='<%# Bind("loanTimeID") %>'></asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDSTime" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [tblLoanTime]"></asp:SqlDataSource>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblTime" runat="server" Text='<%# Bind("loanTimeDesc") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="loanTimeDesc" HeaderText="Loan Length" SortExpression="loanTimeDesc" HeaderStyle-CssClass="hidecol" ItemStyle-CssClass="hidecol"  >
<HeaderStyle CssClass="hidecol"></HeaderStyle>
<ItemStyle CssClass="hidecol"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField DataField="borrowerName" HeaderText="Borrower Name" SortExpression="borrowerName"/>
            <asp:TemplateField HeaderText="Status" SortExpression="status">
                <EditItemTemplate>
                    <asp:DropDownList ID="dropDownStatuses" runat="server" SelectedValue='<%# Bind("status") %>'>
                        <asp:ListItem>Loaned</asp:ListItem>
                        <asp:ListItem>Returned</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("status") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="loanID" HeaderText="loanID" InsertVisible="False" ReadOnly="True" SortExpression="loanID" Visible="false" />
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update" CssClass="btn btn-primary"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" CssClass="btn btn-danger"></asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" CssClass="btn btn-primary"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm ('Are you sure you want to delete this record?');" CssClass="btn btn-danger"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="productID" HeaderText="productID" SortExpression="productID" HeaderStyle-CssClass="hidecol" ItemStyle-CssClass="hidecol" >
<HeaderStyle CssClass="hidecol"></HeaderStyle>
<ItemStyle CssClass="hidecol"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField DataField="loanerEmail" HeaderText="loanerEmail" SortExpression="loanerEmail" HeaderStyle-CssClass="hidecol" ItemStyle-CssClass="hidecol" >
<HeaderStyle CssClass="hidecol"></HeaderStyle>
<ItemStyle CssClass="hidecol"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField DataField="borrowerEmail" HeaderText="borrowerEmail" SortExpression="borrowerEmail" HeaderStyle-CssClass="hidecol" ItemStyle-CssClass="hidecol" >
<HeaderStyle CssClass="hidecol"></HeaderStyle>
<ItemStyle CssClass="hidecol"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField DataField="borrowerPhone" HeaderText="borrowerPhone" SortExpression="borrowerPhone" HeaderStyle-CssClass="hidecol" ItemStyle-CssClass="hidecol" >
<HeaderStyle CssClass="hidecol"></HeaderStyle>
<ItemStyle CssClass="hidecol"></ItemStyle>
            </asp:BoundField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDSDevices" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT tblLoanDevice.loanID, tblLoanDevice.productID, tblLoanDevice.dateBorrow, tblLoanDevice.loanTimeID, tblLoanDevice.loanerName, tblLoanDevice.loanerEmail, tblLoanDevice.borrowerEmail, tblLoanDevice.borrowerPhone, tblLoanDevice.borrowerName, tblLoanDevice.status, tblProducts.productName, tblLoanTime.loanTimeDesc FROM tblLoanDevice INNER JOIN tblLoanTime ON tblLoanDevice.loanTimeID = tblLoanTime.loanTimeID INNER JOIN tblProducts ON tblLoanDevice.productID = tblProducts.productID WHERE (tblLoanDevice.status = @status) OR @status is NULL AND (tblLoanDevice.loanTimeID= @loanTimeID) OR @loanTimeID is NULL" DeleteCommand="DELETE FROM [tblLoanDevice] WHERE [loanID] = @loanID" InsertCommand="INSERT INTO [tblLoanDevice] ([productID], [dateBorrow], [loanTimeID], [loanerName], [loanerEmail], [borrowerEmail], [borrowerPhone], [borrowerName], [status]) VALUES (@productID, @dateBorrow, @loanTimeID, @loanerName, @loanerEmail, @borrowerEmail, @borrowerPhone, @borrowerName, @status)" UpdateCommand="UPDATE [tblLoanDevice] SET [productID] = @productID, [dateBorrow] = @dateBorrow, [loanTimeID] = @loanTimeID, [loanerName] = @loanerName, [loanerEmail] = @loanerEmail, [borrowerEmail] = @borrowerEmail, [borrowerPhone] = @borrowerPhone, [borrowerName] = @borrowerName, [status] = @status WHERE [loanID] = @loanID" CancelSelectOnNullParameter="False" >
        <DeleteParameters>
            <asp:Parameter Name="loanID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="productID" Type="Int32" />
            <asp:Parameter DbType="Date" Name="dateBorrow" />
            <asp:Parameter Name="loanTimeID" Type="Int32" />
            <asp:Parameter Name="loanerName" Type="String" />
            <asp:Parameter Name="loanerEmail" Type="String" />
            <asp:Parameter Name="borrowerEmail" Type="String" />
            <asp:Parameter Name="borrowerPhone" Type="String" />
            <asp:Parameter Name="borrowerName" Type="String" />
            <asp:Parameter Name="status" Type="String" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="dropdownStatus" Name="status" PropertyName="SelectedValue" ConvertEmptyStringToNull="true" />
            <asp:ControlParameter ControlID="dropDownTime" Name="loanTimeID" PropertyName="SelectedValue" ConvertEmptyStringToNull="true" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="productID" Type="Int32" />
            <asp:Parameter DbType="Date" Name="dateBorrow" />
            <asp:Parameter Name="loanTimeID" Type="Int32" />
            <asp:Parameter Name="loanerName" Type="String" />
            <asp:Parameter Name="loanerEmail" Type="String" />
            <asp:Parameter Name="borrowerEmail" Type="String" />
            <asp:Parameter Name="borrowerPhone" Type="String" />
            <asp:Parameter Name="borrowerName" Type="String" />
            <asp:Parameter Name="status" Type="String" />
            <asp:Parameter Name="loanID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>